/**
 入驻小区
 **/
(function (vc) {
    vc.extends({
        data: {
            roomCreateFeeInfo: {
                roomName: '',
                roomId: '',
                ownerId: '',
                ownerName: '',
                roomType: '',
                _currentTab: 'simplifyRoomFee',
                condition: {
                    roomNum: '',
                    ownerName: '',
                }
            },
        },
        _initMethod: function () {
            vc.emit('roomTreeDiv', 'initRoomTreeDiv', {
                callName: 'roomCreateFee'
            });
        },
        _initEvent: function () {
            vc.on('roomCreateFee', 'selectRoom', function (_param) {
                $that.roomCreateFeeInfo.ownerName = '';
                $that.roomCreateFeeInfo.ownerId = '';
                $that.roomCreateFeeInfo.roomId = _param.roomId;
                $that.roomCreateFeeInfo.roomName = _param.roomName;

                $that.roomCreateFeeInfo.condition.ownerName = '';
                $that.roomCreateFeeInfo.condition.roomNum = '';
                $that.listRoomInRoomCreateFee();
            });
            vc.on('roomCreateFee', 'notifyRoomByOwner', function (_room) {
                vc.copyObject(_room, $that.roomCreateFeeInfo);
                $that.roomCreateFeeInfo.roomId = _room.roomId;
                $that.roomCreateFeeInfo.roomName = _room.floorNum + "-" + _room.unitNum + "-" + _room.roomNum;
                $that.listRoomInRoomCreateFee();
            });

        },
        methods: {
            listRoomInRoomCreateFee: function () {
                let param = {
                    params: {
                        page: 1,
                        row: 1,
                        communityId: vc.getCurrentCommunity().communityId,
                        roomId: $that.roomCreateFeeInfo.roomId,
                    }
                };
                if ($that.roomCreateFeeInfo.condition.roomNum) {
                    param.params.flag = '1';
                    param.params.roomNum = $that.roomCreateFeeInfo.condition.roomNum;
                    param.params.roomId = '';
                    $that.roomCreateFeeInfo.roomName = "";
                    $that.roomCreateFeeInfo.ownerName = "";
                    $that.roomCreateFeeInfo.ownerId = "";
                    $that.roomCreateFeeInfo.roomId = "";

                }
                //发送get请求
                vc.http.apiGet('/room.queryRooms',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        vc.copyObject(_json.rooms[0], $that.roomCreateFeeInfo);
                        $that.changeTab('simplifyRoomFee');

                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },



            _inputRoomByOwner: function () {
                if ($that.roomCreateFeeInfo.timer) {
                    clearTimeout($that.roomCreateFeeInfo.timer)
                }
                $that.roomCreateFeeInfo.timer = setTimeout(() => {
                    vc.emit('inputSearchRoomByOwner', 'searchRoom', {
                        callComponent: 'roomCreateFee',
                        ownerName: $that.roomCreateFeeInfo.condition.ownerName
                    });
                }, 1500)
            },
            //查询
            _queryRoomCreateFeeMethod: function () {
                // 关闭查询组件
                $that.listRoomInRoomCreateFee();
            },
            //重置
            _resetRoomCreateFeeMethod: function () {

                // 关闭查询组件
                vc.emit('inputSearchRoomInfo', 'close', {});
                vc.emit('inputSearchRoomByOwner', 'close', {});
                $that.roomCreateFeeInfo.roomNum = "";
                $that.roomCreateFeeInfo.ownerName = "";
                $that.roomCreateFeeInfo.ownerId = "";
                $that.roomCreateFeeInfo.condition.ownerName = '';
                $that.roomCreateFeeInfo.condition.roomNum = '';
                $that.changeTab('simplifyRoomFee');
            },

            changeTab: function (_tab) {
                $that.roomCreateFeeInfo._currentTab = _tab;
                vc.emit(_tab, 'switch', {
                    ownerId: $that.roomCreateFeeInfo.ownerId,
                    ownerName: $that.roomCreateFeeInfo.ownerName,
                    roomId: $that.roomCreateFeeInfo.roomId,
                    roomName: $that.roomCreateFeeInfo.roomName,
                })
            },
            _roomCreateFeetoSimplifyAcceptance: function () {
                let _date = new Date();
                vc.saveData("JAVA110_IS_BACK", _date.getTime());
                vc.saveData('simplifyAcceptanceSearch', {
                    searchType: '1',
                    searchValue: $that.roomCreateFeeInfo.floorNum + "-" + $that.roomCreateFeeInfo.unitNum + "-" + $that.roomCreateFeeInfo.roomNum,
                    searchPlaceholder: '请输入房屋编号 楼栋-单元-房屋 如1-1-1',
                })
                vc.jumpToPage('/#/pages/property/simplifyAcceptance?tab=业务受理');
            },
            _toBatchCreateFee: function (_room, _isMore) {
                vc.jumpToPage('/#/pages/fee/roomCreatePayFee')
            },
            _downloadCollectionLetterOrder: function () {
                vc.jumpToPage('/#/pages/fee/addOweFeeCallable?callableWay=EXCEL');
            },
            _downloadRoomCollectionLetterOrder: function (_room) {
                vc.emit('downloadCollectionLetterOrder', 'openExportExcel', {
                    roomId: _room.roomId
                })
            },
            _openFeeImportExcel: function () {
                vc.emit('exportFeeImportExcel', 'openExportFeeImportExcelModal', {})
            },
            _openDoCreateRoomFee: function () {
                vc.emit('doImportCreateFee', 'openDoImportCreateFeeModal', {})
            },
            _openRoomCreateFeeComboModal: function () {
                vc.jumpToPage('/#/pages/property/createFeeByCombo?payerObjId=' +
                    $that.roomCreateFeeInfo.roomId +
                    "&payerObjName=" + $that.roomCreateFeeInfo.roomName +
                    "&payerObjType=3333")
            },
            _exportRoomCreateFee: function () {
                $that.roomCreateFeeInfo.conditions.communityId = vc.getCurrentCommunity().communityId;
                // $that.roomCreateFeeInfo.conditions.payerObjId=  $that.roomCreateFeeInfo.conditions.roomId;
                $that.roomCreateFeeInfo.conditions.pagePath = 'roomCreateFee';
                let param = {
                    params: $that.roomCreateFeeInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/export.exportData', param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        vc.toast(_json.msg);
                        if (_json.code == 0) {
                            vc.jumpToPage('/#/pages/property/downloadTempFile?tab=下载中心')
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    });
            },
            _splitPayFee: function (_fee) {
                vc.emit('splitFee', 'openSplitFeeModal', _fee);
            }
        }
    });
})(window.vc);